/*
										Melonracer Redux by Stephen Swires & Gmod4Ever
	==================================================================================================================================================
	The MIT License
	Copyright (c) 2006 Stephen Swires & Gmod4Ever

	Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in
	the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
	Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
	WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
	OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
	OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
	==================================================================================================================================================
*/

include( 'shared.lua' )

flLapTime 0.00 // btw you can't cheat with this, it's just for clientside approximation of your laptime.

// macro for resolving a vector, into a scalar (2d)
function MRResolveVector( ResMe )
	return ResMe:Length()
end

// macro for converting to miles per hour
function MRMilesPerHour( InchesPerSecond )
	return InchesPerSecond * 0.056818181
end

// macro for converting mph to km/h
function MRMilesToKM( Miles )
	return Miles * 1.6093
end

function GM:Initialize( )	
	self.BaseClass:Initialize()
	
	// fonts go here
	surface.CreateFont( "Impact", 24, 400, false, false, "MRFImpactText" )
	surface.CreateFont( "Tahoma", 18, 400, false, false, "MRFMiniText" )
end

// hud drawing stuff all goes here.
function GM:HUDPaint()

	local Melon = LocalPlayer():GetNetworkedEntity( "Melon" ) // get our melon ent.
	
	if( Melon:IsValid() ) then // we're a melon
		// SPEED
		local MelVel = Melon:GetVelocity()
		local MelSpeed = MRResolveVector( MelVel )
	
		Msg( "Calculated Speed: " .. MelSpeed .. "\n")
		
		// right, some converstions
		local MelMPH = MRMilesPerHour( MelSpeed )
		local MelKPH = MRMilesToKM( MelMPH )
	
		// draw.RoundedBox( Number Bordersize, Number X, Number Y, Number W, Number H, Table Colour )
		draw.RoundedBox( 1, 15, ScrH() - 50, 150, 45, Color( 0, 0, 0, 150 ) )
		draw.SimpleText( "" .. math.Round(MelMPH) .. " mph", "MRFImpactText", 20, ScrH() - 45, Color( 255, 255, 255 ) ) // draw mph (go imperial system!)
		draw.SimpleText( "" .. math.Round(MelKPH) .. " km/h", "MRFMiniText", 155, ScrH() - 28, Color( 150, 150, 150 ), TEXT_ALIGN_RIGHT ) // draw km/h before metric lovers complain
	end

end
